package com.demo.controller_admin;

import java.util.List;

import javax.annotation.Resource;

import org.apache.tomcat.util.buf.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.demo.entity.CourseSection;
import com.demo.service_admin.CourseSectionService;

@Controller("adminCourseSectionController")
@RequestMapping(value = "/${site.adminUrlPrefix}/course_section")
public class CourseSectionController {
	
	@Resource(name = "adminCourseSectionService")
	CourseSectionService courseSectionService;
	
	/**
	 * 动态查询课程
	 * @param p
	 * @param course
	 * @return
	 */
	@GetMapping(value = "/search")
	public @ResponseBody Page<CourseSection> findAll(Integer p, CourseSection courseSection) {
		if(p==null)	p=1;
		Sort sort = new Sort(Sort.Direction.ASC, "id");
		Pageable pageable = PageRequest.of(p, 10, sort);
		return courseSectionService.findAll(courseSection, pageable);
	}
	
	/**
	 * 批量软删除
	 * @param id
	 * @return
	 */
	@GetMapping(value = "/batchDelete")
	public @ResponseBody String batchDelete(Long[] id) {
		if(id!=null && id.length>0) 
			return String.valueOf(courseSectionService.batchDelete(id));
		return "缺少参数id";
	}

}